package talk.dapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.github.chrisbanes.photoview.PhotoView;
import com.talk.debby.talk.R;

import java.util.List;

import io.rong.imageloader.core.ImageLoader;


/**
 * Created by debby on 2018/5/22.
 * 描述:
 */

public class MyViewPagerAdapter extends PagerAdapter {

    private List<String> images;

    private Context mContext;

    public MyViewPagerAdapter(Context context, List<String> images) {
        this.mContext = context;
        this.images = images;
    }

    @Override
    public int getCount() {
        return images.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }


    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        String imgUrl = images.get(position);
        LinearLayout view = (LinearLayout) LayoutInflater.from(mContext)
                .inflate(R.layout.adpter_photo_view, null);
        PhotoView img = view.findViewById(R.id.pv_main);
        img.setTag(imgUrl);
//        Glide.with(mContext).load(imgUrl).into(img);
        ImageLoader.getInstance().displayImage(imgUrl, img);
        container.addView(view);
        return view;
    }
}
